﻿/*
 * ----------------------------------------------------------------
 * Copyright @ @@神农写代码 2023. All rights reserved.
 
 * 作    者 ：@@神农写代码 
 
 * 创建时间 ：2023/2/3 22:05:23
 
 * CLR 版本 ：4.0.30319.42000
 
 * 命名空间 ：GCNF.Algorithm.Polling
 
 * 类 名 称 ：RoundRobin

 * 类 描 述 ：
 
 * 博客地址：fu-shi-rong.blog.csdn.net
 
 * ------------------------------------------------------
 * 历史更新记录
 
 * 版本 ：  V1.0.0.0        修改时间：2023/2/3 22:05:23         修改人：
 
 * 修改内容：
 * 
 */
using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Text;

namespace GCNF.Algorithm.Polling
{
    public class RoundRobin : AbstractRoundRobin
    {

        public override RoundRobinConfiguration Select(List<RoundRobinConfiguration> serviceAddress)
        {
            lock (_lock)
            {
                if (this.roundRobinEnum == RoundRobinEnum.SelectByWeight) 
                {
                     this.AssignWeight(serviceAddress);
                     serviceAddress = this.serviceAddressList;
                }
                if (serviceAddress.Count == 0) return robinConfiguration;
                if (requestCount == serviceAddress.Count)
                {
                    requestCount = 0;
                }
                robinConfiguration = serviceAddress[requestCount];
                requestCount++;
                return robinConfiguration;
            }
        } 
    }
}